#ifndef LXMUSIC_H
#define LXMUSIC_H

#include <QWidget>
#include<QMouseEvent>
#include<QJsonArray>
#include<QDebug>
#include<QGraphicsDropShadowEffect>
#include<QVector>
#include<QJsonObject>
#include"volumetool.h"
#include<QFileDialog>
#include"musiclist.h"
#include<QMediaPlayer>
#include"qmediaplaylist.h"
#include<QAudioOutput>
#include"commonpage.h"
#include"lrcpage.h"
#include<QPropertyAnimation>
#include<QSqlDatabase>
#include<QMessageBox>
#include<QSqlError>
#include<QSqlQuery>
#include<QSystemTrayIcon>
#include<QMenu>
#include <QSharedMemory>

QT_BEGIN_NAMESPACE
namespace Ui {
class LXMusic;
}
QT_END_NAMESPACE

class LXMusic : public QWidget
{
    Q_OBJECT

public:
    LXMusic(QWidget *parent = nullptr);
    ~LXMusic();


public:
    void initUi();
    void initPlayer();
    void connectSignalAndSlots();
    QJsonArray randomPticture();
    void playAllOfPage(CommonPage* page, int index);
    void setMusicHistoryByUrl(QUrl url);
    void initSQlite();
    void initMusiclist();
    void createTray();


protected:
    virtual void mousePressEvent(QMouseEvent* event)override;
    virtual void mouseMoveEvent(QMouseEvent* event)override;


private slots:
    void on_quitButton_clicked();
    void onBtformClicked(int pageId);
    void on_volumeButton_clicked();
    void on_addLocalButton_clicked();
    void onUpdateLikeMusic(bool isLike, QString musicId);
    void onPlayClicked();
    void onPlayStausTochangeIcon();
    void onPlayUpClicked();
    void onPlayDownClicked();
    void onPlaybackModeClicked();
    void finishedAutoplay(QMediaPlayer::PlaybackState state);
    void onPlaybackModeChange(PlaybackMode playbackMode);
    void onPlayAll(PageType type);
    void playMusicByIndex(CommonPage* page, int index);
    void onCurrentIndexChanged(int index);
    void setMusicSilence(bool isMuted);
    void setMusicVolume(int volumeRatio);
    void onDurationChanged(qint64 duration);
    void onPositionChanged(qint64 position);
    void onMusicSliderChanged(float value);
    void onMetaDataChanged();
    void onLrcWordClicked();
    void on_minButton_clicked();
    void on_skinButton_clicked();
    void updateBtFormAnimation();
    void quitLXMusic();

private:
    Ui::LXMusic *ui;

    QPoint _dragPosition;
    VolumeTool* _volumetool;
    MusicList _musicList;

    QMediaPlayer* _player;//播放器
    QMediaPlaylist* _playList;//播放列表

    CommonPage* _currentPlayPage;//当前播放页面

    bool _isManualPlay = false; //标志位，避免手动操作时调用finishedAutoPlay函数

    LrcPage* _lrcWord;

    QPropertyAnimation* _animal;//歌词窗口移动动画

    QSqlDatabase sqlite;//数据库

    bool _isDrag;//标志位，防止点击BtForm的时候窗口乱移

};
#endif // LXMUSIC_H
